<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('core/core')->checklogin('','',true);
	$clerk_id=$this->model('pei')->checkclerk();
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	$saler = pdo_get('jy_supplier_clerk',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$depot = pdo_get('jy_supplier_depot',array('uniacid'=>$_SESSION['uniacid'],'id'=>$saler['depot_id']));
	$member = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$saler['mid']),array('nickname','avatar'));
	$return['saler']=$saler;
	$return['member']=$member;
	$return['depot']=$depot;
	set_html('title','商品入库');
	exi($return);
}
if($_RQ['op']=='up'){
	$clerk_id=$this->model('pei')->checkclerk();
	$logid=$_RQ['id'];
	$goodsid=$_RQ['goodsid'];
	$optionid=intval($_RQ['optionid']);	
	$key=intval($_RQ['key']);	
	$log=pdo_get('jy_supplier_log',array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
	if(empty($log)){
		exi('不存在待入库商品!','error','jy_supplier/goodslog/');
	}
	$goodslog=pdo_get('jy_supplier_goodslog',array('key'=>$key,'optionid'=>$optionid,'goodsid'=>$goodsid,'logid'=>$logid,'uniacid'=>$_SESSION['uniacid']));
	if($goodslog['id']){
		exi('该标签已经入库，请勿重复操作!','error','jy_supplier/goodslog/');
	}
	$log['goods']=json_decode($log['goods'],true);
	foreach($log['goods'] as &$gv){
		if($gv['optionid']==$optionid && $gv['goodsid']==$goodsid){
			$title=$gv['title'];
			$leititle=$gv['leititle'];
		}
	}
	$data=array(
		'logid'=>$logid,
		'goodsid'=>$goodsid,
		'optionid'=>$optionid,
		'key'=>$key,
		'title'=>$title,
		'leititle'=>$leititle,
		'depot_id'=>$log['depot_id'],
		'clerk_id'=>$clerk_id,
		'merchid'=>$log['merchid'],
	);
	$data['createtime']=time()+100;
	$data['uniacid']=$_SESSION['uniacid'];
	$this->pdo_insert('goodslog',$data);
	$return['merch']=pdo_get('jy_supplier_user',array('id'=>$log['merchid'],'uniacid'=>$_SESSION['uniacid']));
	$return['log']=$log;
	$data['unit']=pdo_getcolumn('jy_weishop_goods',array('id'=>$data['goodsid'],'uniacid'=>$_SESSION['uniacid']),'unit');
	$data['image']=pdo_getcolumn('jy_weishop_goods',array('id'=>$data['goodsid'],'uniacid'=>$_SESSION['uniacid']),'image');
	$return['goods']=$data;
	set_html('title','入库商品');
    exi($return);
}